eljaydee Posted March 31, 2019 Share Posted March 31, 2019 (edited) I have been at this for several hours.. <?php $conn = mysqli_connect(localhost, root, mypw, mydb) or die(mysqli_error($conn)); ?> I keep getting: Parse error: syntax error, unexpected '?>', expecting ',' or ')' in C:\Apache24\htdocs\mysql_connect.php on line 4 I have tried copy and paste of mysqli_connect from several different web pages, nothing works. PHP is installed correctly, I have a db in MySQL, and Apache is installed with no errors. what the... Edited March 31, 2019 by eljaydee typo Quote Link to comment Share on other sites More sharing options...
gw1500se Posted March 31, 2019 Share Posted March 31, 2019 Please use the formatter (<>) and PHP. Copying and pasting code is never a good idea. You need to understand what the code is doing to adapt it to your specific application. Since you did not post all your code I can only guess that this is what you should use: $conn = mysqli_connect("localhost","root","mypw","mydb") or die(mysqli_error($conn)); The arguments to connect need to be strings or string variables. Quote Link to comment Share on other sites More sharing options...
eljaydee Posted April 1, 2019 Author Share Posted April 1, 2019 5 hours ago, gw1500se said: <?php $conn = mysqli_connect("localhost","root","6543212Xx!","lm") or die(mysqli_error($conn)); ?> Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in C:\Apache24\htdocs\mysql_connect.php:2 Stack trace: #0 {main} thrown in C:\Apache24\htdocs\mysql_connect.php on line 2 t Quote Link to comment Share on other sites More sharing options...
Barand Posted April 1, 2019 Share Posted April 1, 2019 Check your php.ini file. Ensure mysqli extension is enabled. Also, phpinfo() will tell you - if it is you will have a mysqli section. Quote Link to comment Share on other sites More sharing options...
eljaydee Posted April 1, 2019 Author Share Posted April 1, 2019 11 hours ago, Barand said: Check your php.ini file. Ensure mysqli extension is enabled. Also, phpinfo() will tell you - if it is you will have a mysqli section. yes, i enabled extension mysqli and have error notifications on... still can't get anything to work: i cannot understand why it is saying $conn=mysqli_connect() is undefined... Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in C:\Apache24\htdocs\mysql_connect.php:2 Stack trace: #0 {main} thrown in C:\Apache24\htdocs\mysql_connect.php on line 2 Quote Link to comment Share on other sites More sharing options...
gw1500se Posted April 1, 2019 Share Posted April 1, 2019 Post this code: C:\Apache24\htdocs\mysql_connect.php Quote Link to comment Share on other sites More sharing options...
eljaydee Posted April 1, 2019 Author Share Posted April 1, 2019 phpinfo shows mysqlnd and NOT mysqli, but i am certain i have mysqli enabled in the .ini file ;extension=mbstring ;extension=exif ; Must be after mbstring as it depends on it extension=mysqli ;extension=oci8_12c ; Use with Oracle Database 12c Instant Client ;extension=odbc Quote Link to comment Share on other sites More sharing options...
eljaydee Posted April 1, 2019 Author Share Posted April 1, 2019 It shows what is in the mysql_connect.php file: <?php $conn = mysqli_connect("localhost"," root", "123456" ,"myDB"); ?> Now I get this: This page isn’t working localhost is currently unable to handle this request. HTTP ERROR 500 Quote Link to comment Share on other sites More sharing options...
Barand Posted April 1, 2019 Share Posted April 1, 2019 Extension names begin with php_ (windows) extension=php_mysqli.dll (linux) extension=php_mysqli.so Quote Link to comment Share on other sites More sharing options...
eljaydee Posted April 1, 2019 Author Share Posted April 1, 2019 This is copied right outta my php.ini file: ;extension=bz2 ;extension=curl ;extension=fileinfo ;extension=gd2 ;extension=gettext ;extension=gmp ;extension=intl ;extension=imap ;extension=interbase ;extension=ldap ;extension=mbstring ;extension=exif ; Must be after mbstring as it depends on it extension=mysqli ;extension=oci8_12c ; Use with Oracle Database 12c Instant Client ;extension=odbc ;extension=openssl ;extension=pdo_firebird ;extension=pdo_mysql ;extension=pdo_oci ;extension=pdo_odbc ;extension=pdo_pgsql ;extension=pdo_sqlite ;extension=pgsql ;extension=shmop I added the suggested line: extension=php_mysqli.dll After restarting my computer I am now back to: Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in C:\Apache24\htdocs\mysqli_connect.php:2 Stack trace: #0 {main} thrown in C:\Apache24\htdocs\mysqli_connect.php on line 2 ======================================================================================== It shows what is in the mysql_connect.php file: <?php $conn = mysqli_connect("localhost"," root", "123456" ,"myDB"); ?> Now I get this: This page isn’t working localhost is currently unable to handle this request. HTTP ERROR 500 Quote Link to comment Share on other sites More sharing options...
Barand Posted April 1, 2019 Share Posted April 1, 2019 Check in your extensions folder to see what the names should be EG Quote Link to comment Share on other sites More sharing options...
eljaydee Posted April 1, 2019 Author Share Posted April 1, 2019 yes, and i copied php_mysqli.dll from C:/PHP7/ext to C:/PHP7 ... no change, still doesn't show mysqli in phpinfo, only mysqlnd... Quote Link to comment Share on other sites More sharing options...
Barand Posted April 1, 2019 Share Posted April 1, 2019 Have you tried restarting the server since you made the ini changes? Quote Link to comment Share on other sites More sharing options...
eljaydee Posted April 1, 2019 Author Share Posted April 1, 2019 i just restarted before replying to you, still get: Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in C:\Apache24\htdocs\mysqli_connect.php:2 Stack trace: #0 {main} thrown in C:\Apache24\htdocs\mysqli_connect.php on line 2 this is supposed to be really easy and so far i have found nothing that will resolve this matter...starting to get pretty frustrated... Quote Link to comment Share on other sites More sharing options...
Barand Posted April 1, 2019 Share Posted April 1, 2019 Switch to PDO. It's much better than mysqli. Quote Link to comment Share on other sites More sharing options...
eljaydee Posted April 1, 2019 Author Share Posted April 1, 2019 shrugs... thanks for your efforts... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.