Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Fatal error: Call to undefined function mysqli_connect()

    I installed mysql server 5.1 and no error happens during the installation so I assume everything is fine but when I'm learning and trying to use php and to connect through mysql and there is this error message saying
    Code:
    Fatal error: Call to undefined function mysqli_connect() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\books.php on line 3

    My codes are here

    Code:
    <?php
    
    	$db = mysqli_connect("localhost", "root", "3308") or die(mysqli_connect_error());
    
    mysqli_select_db($db, "booksdb") or die(mysqli_error($db));
    
    	mysqli_query($db, "CREATE TABLE books(
    	id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
    	title VARCHAR(64) NOT NULL)") or die(mysqli_error($db));
    	
    	mysqli_query($db, "INSERT INTO books(id, title) VALUES(NULL, 'the nose')") or die(mysqli_error());
    
    	mysqli_query($db, "INSERT INTO books(id, title) VALUES(NULL, 'the overcoat')") or die(mysqli_error());
    
    	mysqli_query($db, "INSERT INTO books(id, title) VALUES(NULL, 'war and peace')") or die(mysqli_error());
    	
    	$result = mysqli_query($db, "SELECT id, title FROM books") or die(mysqli_error());
    	
    	while($record = mysqli_fetch_assoc($result)){
    		echo $record['id'];
    		echo " ";
    		echo $record['title'];
    		echo "<hr/>";
    	}	
    ?>
    in my php.ini file I did uncomment both

    Code:
    extension=php_mysql.dll
    extension=php_mysqli.dll
    and of course restarted apache. Also restarted the who machine too but that error message keeps on coming up and I have no idea how to fix it. I searched a few forums and they all asked to make sure the extension is uncommented which they are.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,869
    Thanks
    79
    Thanked 4,421 Times in 4,386 Posts
    Well, not to ask a silly question, but how about trying to connect using the old mysql library, instead of mysqli??? If that doesn't work, either, than you have a flawed installation. Missing stuff. If that works, then you may still have a flawed installation, but at least you know it isn't because you forgot to uncomment the DLL.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Well, not to ask a silly question, but how about trying to connect using the old mysql library, instead of mysqli??? If that doesn't work, either, than you have a flawed installation. Missing stuff. If that works, then you may still have a flawed installation, but at least you know it isn't because you forgot to uncomment the DLL.
    how can I do that connecting using old mysql? Sorry I'm really new at this and I was taught using mysqli in the codes. Does that mean I should try typing mysql instead of mysqli?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,869
    Thanks
    79
    Thanked 4,421 Times in 4,386 Posts
    http://www.php.net/manual/en/mysql.examples-basic.php

    But you don't really want to use the older interface.

    Just try to make a connection using mysql_connect(), to see if the interface is there at all.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You're using a windows build of PHP with mysqli.
    Make sure you follow this documentation exactly: http://www.php.net/manual/en/mysqli.installation.php
    Also, check your httpd error logs. I'm willing to bet that its not finding libmysql.dll (which also assumes you are on < 5.3 PHP).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #6
    New Coder
    Join Date
    Jun 2012
    Location
    New York
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post
    create a php info file and check mysqli is included in your PHP installation. If it's not you'll have to recompile php with mysqli included (on Linux) or include the dll in php.ini (in Windows).


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •