0

I am working on an assignment that requires me to create a form that sends info to a database. I am having issues connecting to the server.

I have tried using mysql_connect and mysqli_connect and neither work.

mysql_connect error: Warning: mysql_connect(): Connection timed out

mysqli_connect error: Fatal error: Call to undefined function mysqli_connect()

                    $connect=mysql_connect("server.com","username","password","database")
                    or die("Failed to connect to server");
                    mysql_query("INSERT INTO client (title,fname,lname,organization,email,phone,tshirt) VALUES ($title,$fname,$lname,$org,$email,$phone,$tshirt)");

                    $tabledata = mysql_query("SELECT * FROM client");
                    echo "<table>
                    <tr>
                    <th>Title</th>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Organization</th>
                    <th>Email</th>
                    <th>Phone</th>
                    <th>TShirt</th>
                    </tr>";
                    while($row = mysql_fetch_array($tabledata)){
                            echo "<tr>";
                            echo "<td>" . $row['title']  . "</td>";
                            echo "<td>" . $row['fname']  . "</td>";
                            echo "<td>" . $row['lname']  . "</td>";
                            echo "<td>" . $row['org']    . "</td>";
                            echo "<td>" . $row['email']  . "</td>";
                            echo "<td>" . $row['phone']  . "</td>";
                            echo "<td>" . $row['tshirt'] . "</td>";
                            echo "</tr>";
                    }
                    echo "</table>";
                    mysql_close($connect);

Info from PHP INFO

mysql

MySQL Support enabled Active Persistent Links 0 Active Links 0 Client API version mysqlnd 5.0.10 - 20111026 - $Id: e707c415db32080b3752b232487a435ee0372157 $

PDO

PDO support enabled PDO drivers sqlite

pdo_sqlite

PDO Driver for SQLite 3.x enabled SQLite Library 3.7.7.1

sqlite3

SQLite3 support enabled SQLite3 module version 0.7 SQLite Library 3.7.7.1

Directive Local Value Master Value sqlite3.extension_dir no value no value

1
  • Is it a requirement to use the crappy old mysql_query interface? Commented Nov 19, 2013 at 15:19

5 Answers 5

1

First, make sure mysql is running, and if it already is, then I would try installing the mysql extension for your php environment anyhow, just to make sure:

sudo apt-get install php5-mysql libapache2-mod-auth-mysql

Also, you would want to use mysqli_*, not mysql_*

After you attempt installing, just restart apache from there.

Sign up to request clarification or add additional context in comments.

9 Comments

I do not have admin privileges on this server. I'm 99% sure it is already installed.
I got this error: The program 'apt-get' can be found in the following package: * apt [ path: /usr/bin/apt-get, repository: zypp (openSUSE_11.1-0) ] I couldn't find apt-get though
I happened to have the exact same issue once about a year ago, and this was what fixed it. See if you can get someone with root/sudo privileges to run that :) EDIT: What distro is this?
Am I able to check if mysql is running?
Try running the command /etc/init.d/mysql status (or on redhat) /etc/init.d/mysqld status
|
0

First, are you connecting locally or externally to your DB? If you're connecting locally your parameters for mysql_connect(); would be as follows mysql_connect('localhost', 'username', 'password');

Then:

mysql_select_db('your_db') 

3 Comments

Considering it isn't killing the connection due to incorrect info (and instead an undefined function), I would say it's a different issue.
If he's connecting externally that may be the issue he is having, he'd need to check whether his site allows external IP's
mysql_connect simply returns false on failure, it doesn't magically undefine itself...
0

please use PDO::__construct() or mysqli_connect but in your question

try :

$connect=mysql_connect("server.com","username","password");
mysql_select_db("database");

1 Comment

Same issue... connection timeout
0

Is "server.com" this the real thing you're trying to connect to? Are you connecting to mysql on the local machine or is it external? Try a telnet from the php server:

telnet <remote db name/IP> 3306

If that fails, you have a network/firewall problem. Or the DB is is not listening on that port or on the network entirely. Do a netstat on the remote DB to confirm: Linux

netstat -an | grep LISTENING

You should see :3306 if it's listening on the default port.

Comments

0

check whether you have enabled mysqli.dll in php ini file

with

<?php phpinfo(); ?>

if it isn't enable it in php.ini file //remove ';' from dll name

for more info to check

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.