newbie problem
am 07.08.2006 15:13:14 von tony
Hi guys
I'm new to PHP and I'm trying the following:
mysqli_connect ("localhost","root","mypassword",);
mysqli_select_db (mads);
$result=mysqli_query (SELECT * FROM clients);
print ($result);
?>
According to me (no great authority I know) this should print the array
from the clients table. I can execute the query from the command line
and it works fine. However, when I try to run the script nothing
happens. I've tried everything I can think of-PHP, Mysql and Apache are
all working (I can use PHPmyAdmin).
I must be doing something wrong. What is it?
btw
suse 10.1 with standard installs of everything.
Re: newbie problem
am 07.08.2006 15:24:37 von Rik
tony wrote:
> Hi guys
> I'm new to PHP and I'm trying the following:
>
>
> mysqli_connect ("localhost","root","mypassword",);
> mysqli_select_db (mads);
> $result=mysqli_query (SELECT * FROM clients);
>
> print ($result);
>>
>
> According to me (no great authority I know) this should print the
> array from the clients table. I can execute the query from the
> command line and it works fine. However, when I try to run the script
> nothing happens. I've tried everything I can think of-PHP, Mysql and
> Apache are all working (I can use PHPmyAdmin).
>
> I must be doing something wrong. What is it?
1. mysqli_select_db (mads); should be mysqli_select_db ('mads');
2. $result is a resource, not a string or array.
3. Only strings & numbers can be printed.
Use mysqli_fetch_assoc($result) after your query, normally something like
this:
while($row = mysqli_fetch_assoc($result)){
print(implode(',',$row));
}
Grtz,
--
Rik Wasmus
Re: newbie problem
am 07.08.2006 16:54:11 von tony
Rik wrote:
> tony wrote:
>
>>Hi guys
>>I'm new to PHP and I'm trying the following:
>>
>>
>>mysqli_connect ("localhost","root","mypassword",);
>>mysqli_select_db (mads);
>>$result=mysqli_query (SELECT * FROM clients);
>>
>>print ($result);
>>
>>According to me (no great authority I know) this should print the
>>array from the clients table. I can execute the query from the
>>command line and it works fine. However, when I try to run the script
>>nothing happens. I've tried everything I can think of-PHP, Mysql and
>>Apache are all working (I can use PHPmyAdmin).
>>
>>I must be doing something wrong. What is it?
>
>
> 1. mysqli_select_db (mads); should be mysqli_select_db ('mads');
> 2. $result is a resource, not a string or array.
> 3. Only strings & numbers can be printed.
>
> Use mysqli_fetch_assoc($result) after your query, normally something like
> this:
> while($row = mysqli_fetch_assoc($result)){
> print(implode(',',$row));
> }
>
> Grtz,
Thanx for the reply Rik, unfortunatley that didn't work.
I tried to step back a step and try the following:
print ('hey there');
mysqli_connect ("localhost","root","Xtasy66");
mysqli_select_db ('mads');
$result=mysqli_query(SELECT * FROM clients);
?>
When I execute the first 3 lines I get "hey there". However, when I add
the last line I get nothing. My conclusion is there's somthing wrong
with this line. The only problem is I can't see what it is.
Can you help?
thanx
Re: newbie problem
am 07.08.2006 19:21:46 von Rik
tony wrote:
> Rik wrote:
>> tony wrote:
>>
>>> Hi guys
>>> I'm new to PHP and I'm trying the following:
>>>
>>>
>>> mysqli_connect ("localhost","root","mypassword",);
>>> mysqli_select_db (mads);
>>> $result=mysqli_query (SELECT * FROM clients);
>>>
>>> print ($result);
>>>
>>> According to me (no great authority I know) this should print the
>>> array from the clients table. I can execute the query from the
>>> command line and it works fine. However, when I try to run the
>>> script nothing happens. I've tried everything I can think of-PHP,
>>> Mysql and Apache are all working (I can use PHPmyAdmin).
>>>
>>> I must be doing something wrong. What is it?
>>
>>
>> 1. mysqli_select_db (mads); should be mysqli_select_db ('mads');
>> 2. $result is a resource, not a string or array.
>> 3. Only strings & numbers can be printed.
>>
>> Use mysqli_fetch_assoc($result) after your query, normally something
>> like this:
>> while($row = mysqli_fetch_assoc($result)){
>> print(implode(',',$row));
>> }
>>
>> Grtz,
> Thanx for the reply Rik, unfortunatley that didn't work.
>
> I tried to step back a step and try the following:
>
>
> print ('hey there');
> mysqli_connect ("localhost","root","Xtasy66");
> mysqli_select_db ('mads');
> $result=mysqli_query(SELECT * FROM clients);
>>
>
> When I execute the first 3 lines I get "hey there". However, when I
> add the last line I get nothing. My conclusion is there's somthing
> wrong
> with this line. The only problem is I can't see what it is.
>
> Can you help?
It would mean you have a fatal error somewhere.
Add this at the beginning of the script:
ini_set('display_errors','On');
error_reporting(E_ALL);
?>
Check which errors are reported.
I've never really worked with mysqli before, because it wasn't on the
production servers, but contrary to mysql, mysqli seems to want the explicit
links;
$link = mysqli_connect ("localhost","root","Xtasy66");
mysqli_select_db ($link,'mads');
$result = mysqli_query($link,SELECT * FROM clients);
?>
However, posting you password (if it's indeed you password) here is a Bad
Idea. Please change it as soon as possible.
Grtz,
--
Rik Wasmus
Re: newbie problem
am 07.08.2006 19:36:59 von Rik
Rik wrote:
> $result = mysqli_query($link,SELECT * FROM clients);
Silly me:
$result = mysqli_query($link,'SELECT * FROM clients');
Grtz,
--
Rik Wasmus
Re: newbie problem
am 08.08.2006 03:43:35 von tony
Rik wrote:
> Rik wrote:
>
>>$result = mysqli_query($link,SELECT * FROM clients);
>
>
> Silly me:
> $result = mysqli_query($link,'SELECT * FROM clients');
>
> Grtz,
Rik
You've done it-it worx. It seems that mysqli requires you to define a
connection variable when you run a query and put that b4 the query.
Anything else doesn't work. Hmm, very fussy.
Thanx for all your help rik-and yes I've changed the psswrd. I posted
that just b4 I went to bed and I was lying there thinking "did I post my
psswd?". Don't worry, the machine was shut down.
thanx again for all your help. I'll let you know how far I get 2day!
Re: newbie problem
am 09.08.2006 00:28:29 von Injam
Rik,
I was having almost the same problem. Blank screen, could not figure
out where the problem was. But that sweet chunk of code that prints out
errors help find out where the error was.
ini_set('display_errors','On');
error_reporting(E_ALL);
?>
Thanks,
Injam
Rik wrote:
> tony wrote:
> > Rik wrote:
> >> tony wrote:
> >>
> >>> Hi guys
> >>> I'm new to PHP and I'm trying the following:
> >>>
> >>>
> >>> mysqli_connect ("localhost","root","mypassword",);
> >>> mysqli_select_db (mads);
> >>> $result=mysqli_query (SELECT * FROM clients);
> >>>
> >>> print ($result);
> >>>
> >>> According to me (no great authority I know) this should print the
> >>> array from the clients table. I can execute the query from the
> >>> command line and it works fine. However, when I try to run the
> >>> script nothing happens. I've tried everything I can think of-PHP,
> >>> Mysql and Apache are all working (I can use PHPmyAdmin).
> >>>
> >>> I must be doing something wrong. What is it?
> >>
> >>
> >> 1. mysqli_select_db (mads); should be mysqli_select_db ('mads');
> >> 2. $result is a resource, not a string or array.
> >> 3. Only strings & numbers can be printed.
> >>
> >> Use mysqli_fetch_assoc($result) after your query, normally something
> >> like this:
> >> while($row = mysqli_fetch_assoc($result)){
> >> print(implode(',',$row));
> >> }
> >>
> >> Grtz,
> > Thanx for the reply Rik, unfortunatley that didn't work.
> >
> > I tried to step back a step and try the following:
> >
> >
> > print ('hey there');
> > mysqli_connect ("localhost","root","Xtasy66");
> > mysqli_select_db ('mads');
> > $result=mysqli_query(SELECT * FROM clients);
> >>
> >
> > When I execute the first 3 lines I get "hey there". However, when I
> > add the last line I get nothing. My conclusion is there's somthing
> > wrong
> > with this line. The only problem is I can't see what it is.
> >
> > Can you help?
>
>
> It would mean you have a fatal error somewhere.
> Add this at the beginning of the script:
>
> ini_set('display_errors','On');
> error_reporting(E_ALL);
> ?>
>
> Check which errors are reported.
>
> I've never really worked with mysqli before, because it wasn't on the
> production servers, but contrary to mysql, mysqli seems to want the explicit
> links;
>
> $link = mysqli_connect ("localhost","root","Xtasy66");
> mysqli_select_db ($link,'mads');
> $result = mysqli_query($link,SELECT * FROM clients);
> ?>
>
> However, posting you password (if it's indeed you password) here is a Bad
> Idea. Please change it as soon as possible.
>
> Grtz,
> --
> Rik Wasmus