12 Replies - 598 Views - Last Post: 22 April 2013 - 07:47 PM Rate Topic: -----

#1 AggressiveFish  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 21-April 11

MySQL

Posted 22 April 2013 - 04:22 PM

I have the following in my script
    $con=mysqli_connect("localhost", "username", "password", "sports_database");



and I get the following error:
Fatal error: Call to undefined function mysqli_connect() in C:\inetpub\wwwroot\cgi-bin\test.php on line 2

I checked the PHP directory and I see no hint of MySQL (no exes, folder, etc..,). I'm using PHP 5.4.13. What additional steps do I need to take to connect to MySQL? MySQL is up and running fine, it's all running on a Windows 7 machine. Any help would be appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: MySQL

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2999
  • View blog
  • Posts: 10,383
  • Joined: 08-August 08

Re: MySQL

Posted 22 April 2013 - 04:53 PM

... oops ...
Hang on..

This post has been edited by CTphpnwb: 22 April 2013 - 04:54 PM

Was This Post Helpful? 1
  • +
  • -

#3 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10595
  • View blog
  • Posts: 39,236
  • Joined: 27-December 08

Re: MySQL

Posted 22 April 2013 - 04:56 PM

For reference: list of deprecated MySQLi functions.
Installing and Configuring MySQLi.

Really, PDO is easy to configure for other databases, so it makes your code more extensible. I'd use that instead of MySQLi given the option.

@CTphpnwb- You were right! The mysqli_connect() function is deprecated. I didn't realize that until now!
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2999
  • View blog
  • Posts: 10,383
  • Joined: 08-August 08

Re: MySQL

Posted 22 April 2013 - 05:20 PM

View Postmacosxnerd101, on 22 April 2013 - 07:56 PM, said:

@CTphpnwb- You were right! The mysqli_connect() function is deprecated. I didn't realize that until now!

A happy accident. I didn't know it either!

I too prefer PDO, but for those who want to use mysqli it seems the preferred method is to do:

$mysqli = new mysqli("localhost", "user", "password", "database");


Was This Post Helpful? 1
  • +
  • -

#5 AggressiveFish  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 21-April 11

Re: MySQL

Posted 22 April 2013 - 06:01 PM

I can\'t simply put in mysqli into my PHP script, correct? I tried that as well and again an error. I'm pretty sure both were influenced in the introduction of version 5 PHP weren't they? I try
$con= new mysqli("localhost", "username", "password", "sports_database");


and now I get
Fatal error: Class 'mysqli' not found in C:\inetpub\wwwroot\cgi-bin\test.php on line 3


Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2999
  • View blog
  • Posts: 10,383
  • Joined: 08-August 08

Re: MySQL

Posted 22 April 2013 - 06:07 PM

Try this script:
<?php
phpinfo();


and see if mysqli is installed.
Look for something like the attached image in the browser window.

Another option would be to use PDO.

Attached image(s)

  • Attached Image

This post has been edited by CTphpnwb: 22 April 2013 - 06:05 PM

Was This Post Helpful? 0
  • +
  • -

#7 AggressiveFish  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 21-April 11

Re: MySQL

Posted 22 April 2013 - 06:07 PM

There's a C:/PHP/ext/php_sqlite3.dll and a C:/PHP/ext/php_pdo_sqlite.dll however. Should I rename them or perform some other task?
Was This Post Helpful? 0
  • +
  • -

#8 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2999
  • View blog
  • Posts: 10,383
  • Joined: 08-August 08

Re: MySQL

Posted 22 April 2013 - 06:11 PM

sqlite is not mysqli.
You should use PDO if you don't find mysqli support installed.
Was This Post Helpful? 0
  • +
  • -

#9 AggressiveFish  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 21-April 11

Re: MySQL

Posted 22 April 2013 - 06:16 PM

There's a section for mySQLInd 5.0.10, other than this section there's nothing.

So does the PDO come installed automatically?
Was This Post Helpful? 0
  • +
  • -

#10 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2999
  • View blog
  • Posts: 10,383
  • Joined: 08-August 08

Re: MySQL

Posted 22 April 2013 - 06:20 PM

If you have PHP 5.1 or later it does.
Was This Post Helpful? 0
  • +
  • -

#11 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: MySQL

Posted 22 April 2013 - 07:20 PM

It's odd that a PHP 5.4 installation on Windows would not include MySQLi. It should be included by default. You'd actually have to manually tell the compiler to exclude it. How did you install this on your machine?

Have you checked for PDO_MYSQL support? If whoever complied your installation felt the need to disable MySQLi support, I wouldn't assume PDO support for MySQL is included. (Unless the goal is to force PDO on people.) - In the same phpinfo() output CTphpnwb referenced earlier, you can see which drivers PDO supports.

Attached Image
Was This Post Helpful? 0
  • +
  • -

#12 AggressiveFish  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 21-April 11

Re: MySQL

Posted 22 April 2013 - 07:34 PM

Here's a bunch of info that will hopefully shed some light :
In the php.ini file
extension_dir = "C:/PHP/ext"  // changed from being commented out with ;
extension=php_pdo_sqlite.dll  // removed leading ;



Just for testing I'm using the user mysql with the password as mysql as well (for testing)
$database = new PDO('dblib:host=localhost;dbname=swsports', "mysql", "mysql");



In the page if I just put phpinfo() to the screen I get this under PDO
PDO Support with PDO Drivers underneath and sqlite in the right column
pdo_sqlite with SQLite Library underneath and 3.7.7.1 in the right column



In the config section of the phpinfo() printout I see
.... "--without-pdo-mssql" ....



PHO code is
<?php
    $database = new PDO('dblib:host=localhost;dbname=swsports', "mysql", "mysql");
    phpinfo();
?>
<html>
    <body>
        Welcome
    </body>
</html>



Error is
Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0
 
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\inetpub\wwwroot\cgi-bin\test.php:2 Stack trace: #0 C:\inetpub\wwwroot\cgi-bin\test.php(2): PDO->__construct('dblib:host=loca...', 'mysql', 'mysql') #1 {main} thrown in C:\inetpub\wwwroot\cgi-bin\test.php on line 2



Thanks for the help. I really appreciate it.
Was This Post Helpful? 0
  • +
  • -

#13 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: MySQL

Posted 22 April 2013 - 07:47 PM

OK.

Enabling anything to do with SQLite won't help you with MySQL support. It's a completely different thing. - The line --without-pdo-mssql is also in no way related to this. "mssql" stands for Microsoft SQL Sever, which has nothing to do with MySQL.

It would appear that your PHP installation has a major defect. Somebody seems to have gone out of his way to disable any modern methods of accessing MySQL through it. How did you install it? Which installer did you use? Or did you perhaps compile it yourself?

In the C:\PHP\ext directory, is there a "php_pdo_mysql.dll" file? Or a "php_mysqli.dll" file?

P.S.
The connection string for PDO_MYSQL isn't dblib:host..., it's mysql:host....
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1