Hi, I've been trying to set up a webserver for a while now, but with no luck. Here is the problem:-

After I installed PHP,Apache,MySQL into a folder named 'server' on my local machine and followed the relevant steps to set them up; I used the following script to check if mysqli queries were working:

<?php
@ $db = new mysqli('localhost','genericUser','genericPassword','example_db');
if(mysqli_connect_errno())
{
    echo 'Error: Could not connect at this time';
    exit;
}
if($db)
{
    $query = 'select * from news_posts';
    $result = $db->query($query);
    $num_results = $result->num_rows;
    echo 'There are '.$num_results.' rows';
}
$db->close();
?>

Unfortunately it returned the following error messages :-

Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in C:\server\Apache2.2\htdocs\serverResp.php on line 11

Notice: Trying to get property of non-object in C:\server\Apache2.2\htdocs\serverResp.php on line 12

There are rows

Warning: mysqli::close() [mysqli.close]: Couldn't fetch mysqli in C:\server\Apache2.2\htdocs\serverResp.php on line 15

Ive tried everything to resolve these errors, but as yet, nothing has worked. Assuming its something to do with the extension, I've even checked the phpinfo(); , but the output tells me that the mysqli extension is installed.

If anyone can help me with this, it would be greatly appreciated.

I'm running Windows Vista 32bit Ultimate with apache2.2.11,PHP 5.3.0 and MySQL 5.1.36

(Sorry if this turns out to be the wrong section for this. I'm assuming its a php problem.)

Recommended Answers

All 10 Replies

Take that damn @ out from in front of the first line. @ suppresses errors so you can't see them.

Oops missed that one. Ok @ removed and I've now got this additional error:-

Warning: mysqli::mysqli() [mysqli.mysqli]: (00000/0): in C:\server\Apache2.2\htdocs\serverResp.php on line 3

Stupid question, is MySQL actually running?

Yep, just checked.

K, then try the script using plain mysql_query functions. If that works then it's something wrong with mysqli.

Ok ill give it a go, just a sec...

Ok I've tried to produce some similar code with plain queries, but its still erroring :-

Warning: mysqli_connect() [function.mysqli-connect]: (00000/0): in C:\server\Apache2.2\htdocs\serverResp2.php on line 2

Warning: mysqli_select_db() expects parameter 1 to be mysqli, boolean given in C:\server\Apache2.2\htdocs\serverResp2.php on line 3

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in C:\server\Apache2.2\htdocs\serverResp2.php on line 4

Heres the code I used (Its not exactly the same, but close enough for this test):-

<?php
$db = mysqli_connect('localhost','genericUser','genericPassword');
mysqli_select_db($db,"posts_db");
$q = mysqli_query($db,"select * from news_posts");
?>

Now I can only assume that theres something wrong with the mysqli extension...

heh, I said mysql_query, etc. You're still using mysqli

Ok heres an update:

I copied the following script into a file:-

<?php
$link = mysql_connect('localhost', 'postAccessUser', 'smandPlarcel248');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

but got this error from it :-

Warning: mysql_connect() [function.mysql-connect]: in C:\server\Apache2.2\htdocs\serverResp2.php on line 2
Could not connect:

although I'm not sure if that means I've supplied the wrong connection credentials or if its having trouble finding the mysql_connect() function

Edit:The odd thing about this error is the fact that mysql_error() does not produce any value.

Ok, done some reinstalling and testing, and it has somehow fixed the problem. I can only assume that the mysqli files I had used, had become corrupted.

Thank you to ShawnCPlus for the info, and a few pointers as to what might have been wrong with it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.