Enabling MySQLi

smaug8821

[H]ard|Gawd
Joined
Apr 9, 2008
Messages
1,393
Alright, I'm probably missing something pretty obvious, but I'm teaching myself PHP and MySQL, and the book I am using uses MySQLi. I was using my hosting to do my PHP testing, but it seems they don't allow MySQLi, and I don't have access to the php.ini file, so I can't enable it. So I installed PHP, MySQL, and Apache on my computer(probably all a little bit old, this book is from 2006, and I just used the CD it came with).

Anyways, I edited the php.ini file, and these are the steps I took to try to enable MySQLi.

- Edited "extension_dir" to say 'extension_dir = "C:\php\ext"'
- Added "extension=php_mysqli.dll" to the dynamic extensions section
- Changed "mysqli.default_user = "to "mysqli.default_user = root"
- Changed "mysqli.default_host = "to "mysqli.default_host = localhost"

I'm not getting any errors, but I made a simple connect script, and my pages are coming out blank, they aren't even displaying the error.

Code:
<?php

$mysqli = new mysqli("localhost", "root", "****", "smaugDB");

if (mysqli_connect_errno()) {
   printf("Connect failed: %s\n", mysqli_connect_error());
   exit();
}

else {
   printf("Host information: %s\n, mysqli_get_host_info($mysqli));
}

?>

I'm sure I'm missing something really simple, but I've searched around and can't find an answer. So any help is appreciated.

Thanks.
 
you might have "display_errors" turned off in PHP ini. it usually comes that way by default for security reasons.
 
try var_dump($mysqli) to see if it is actually set.

also, set error_reporting=E_ALL in your php.ini in addition to display_errors=on
 
Which OS are you using?

Can you connect to MySQL using any of the command-line tools?
 
try var_dump($mysqli) to see if it is actually set.

also, set error_reporting=E_ALL in your php.ini in addition to display_errors=on
r

I'll try that tomorrow, thanks.

Which OS are you using?

Can you connect to MySQL using any of the command-line tools?

Yeah, I can access MySQL through the command prompt in Windows.
 
Well I'm finally getting back to this..

error_reporting was set to E_ALL

I tried var_dump($mysqli), and I get this error:

Parse error: parse error, unexpected $end in C:\Program Files\Apache Group\Apache2\htdocs\mysqlconnect.php on line 28

This is my code again:

Code:
<html>
<head>
<title>MySQLi Database Connect</title>
</head>

<body>



<?php

$mysqli = new mysqli("localhost", "root", "****", "smaugDB");

if (mysqli_connect_errno()) {
   printf("Connect failed: %s\n", mysqli_connect_error());
   exit();
}

else {
   printf("Host information: %s\n, mysqli_get_host_info($mysqli));
}

var_dump($mysqli);

?>

</body>
</html>

If worst comes to worst I'll just look up a regular MySQL tutorial for now, and attempt to figure this out some other time.
 
I assume if you installed PHP from the CD that came with the book you are using PHP 5? Have you tried using MySQL Administrator to access your database and make sure your users and database are properly setup?
 
<?php
.
.

else {
printf("Host information: %s\n, mysqli_get_host_info($mysqli));
}

var_dump($mysqli);

?>

</body>
</html>
[/CODE]

me thinks you're missing a closing quote in this line
 
Back
Top