Jump to content

As the title says, im having trouble with PHP and MYSQL.

 

I have PHP running on Apache on a Linux server, and MYSQL. I tried running MYSQL on both localhost and another machine on the LAN. In both cases, i can access the MYSQL server via terminal on the same machine. However, I cannot make Apache connect.

 

I tried making a simple "connect" command:

<?php
$con=mysqli_connect("192.168.1.50","web","pass","test");

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
 else
    {
    echo "success"
    }
?>

However, the result returned was::

<html>

<body>

</body>

</html>

 

I have tried many different ways to connect (refrencing the PHP documentation), but nothing seems to work.

 

As far as i know, i have everything setup right. MYSQL user and its privleges, php.ini file configured, ect. The only thing i can think of is i need to install a mod in the "mods_enabled" folder, but i dont see anything refering to MYSQL or MYSQLi in the "mods_available" folder.

Does anyone have any ideas?

~Judah

Link to comment
https://linustechtips.com/topic/91285-mysql-and-php-fighting/
Share on other sites

Link to post
Share on other sites

Sounds like php doesn't like the code. SSH in and run php5 file.php. Also, there's a typo after "success" - missed a semi-colon.

 

darren@vps:~$ php5 test.phpPHP Parse error:  syntax error, unexpected '}', expecting ',' or ';' in /home/darren/test.php on line 10darren@vps:~$ vim test.phpdarren@vps:~$ php5 test.phpPHP Fatal error:  Call to undefined function mysqli_connect() in /home/darren/test.php on line 2
Link to comment
https://linustechtips.com/topic/91285-mysql-and-php-fighting/#findComment-1231873
Share on other sites

Link to post
Share on other sites

As the title says, im having trouble with PHP and MYSQL.

 

I have PHP running on Apache on a Linux server, and MYSQL. I tried running MYSQL on both localhost and another machine on the LAN. In both cases, i can access the MYSQL server via terminal on the same machine. However, I cannot make Apache connect.

 

I tried making a simple "connect" command:

<?php

$con=mysqli_connect("192.168.1.50","web","pass","test");

if (mysqli_connect_errno())

  {

  echo "Failed to connect to MySQL: " . mysqli_connect_error();

  }

 else

    {

    echo "success"

    }

?>

However, the result returned was::

<html>

<body>

</body>

</html>

 

I have tried many different ways to connect (refrencing the PHP documentation), but nothing seems to work.

 

As far as i know, i have everything setup right. MYSQL user and its privleges, php.ini file configured, ect. The only thing i can think of is i need to install a mod in the "mods_enabled" folder, but i dont see anything refering to MYSQL or MYSQLi in the "mods_available" folder.

Does anyone have any ideas?

There are syntax errors in your code, and you really should be using PDO with prepared statements.

 

http://php.net/pdo_mysql

Link to comment
https://linustechtips.com/topic/91285-mysql-and-php-fighting/#findComment-1231915
Share on other sites

Link to post
Share on other sites

Fixed syntax error after "success."

 

Now im working on the "undefinied function mysql_connect" error.

 

 

 

you really should be using PDO with prepared statements.

 

Working on that part. I am very new to running a website, before this year i had nearly no experience running Apache.

~Judah

Link to comment
https://linustechtips.com/topic/91285-mysql-and-php-fighting/#findComment-1231947
Share on other sites

Link to post
Share on other sites

Ive always used $con = new mysqli (host, username, pass, db);

But that that shouldn't change much.

Neither should the difference of single vs double quotes....

Try using a local database? Like one off localhost

I got it to work.

I didn't know mysql support want pre packaged into php. I installed the php-mysql package and it works now (localhost only though).

~Judah

Link to comment
https://linustechtips.com/topic/91285-mysql-and-php-fighting/#findComment-1245079
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×