You are here: Re: newbie problem « PHP SQL « IT news, forums, messages
Re: newbie problem

Posted by Rik on 08/07/06 17:21

tony wrote:
> Rik wrote:
>> tony wrote:
>>
>>> Hi guys
>>> I'm new to PHP and I'm trying the following:
>>>
>>> <?php
>>> 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:
>
> <?php
> 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:
<?php
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;
<?php
$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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация