Questions tagged [mysql-connect]

The `mysql_connect` function opens a connection to a MySQL server.

The mysql_connect function opens a connection to a MySQL server. However, this function, along with all other mysql_* functions, are deprecated in PHP 5.5.0 and should be avoided (see the red box). Consider using prepared statements with either PDO or MySQLi instead.

192 questions
2
votes
2 answers

Behaviour of mysql_connect if called twice

PHP+MySQL, What would happen when calling mysql_connect twice, like that: $link = mysql_connect($server, $user, $pass); $link = mysql_connect($server, $user, $pass); PHP doesn't seem to generate any notice. Is the second line ignored or the new…
Saix
  • 103
  • 9
2
votes
2 answers

"mysql_select_db" fails while "mysql_connect" OK

new here, only starting basic PHP. Trying to understand the specifics of the two MySQL commands. Please see this code
Andrejs
  • 10,803
  • 4
  • 43
  • 48
2
votes
4 answers

MySQL database config in a separate class

Is it possible to keep all my database related configuration (hostnames, usernames, passwords, and databases) as well as the function to connect to and select the correct database in a separate class? I tried something like this: class Database { …
trobrock
  • 46,549
  • 11
  • 40
  • 46
2
votes
2 answers

Remote connection to MySQL works via command line, but fails when using php's mysql_connect from a web browser

I am trying to connect to a MySQL server using PHP's 'mysql_connect()' function, but the connection fails. This is my code: $con = mysql_connect("example.net", "myusername","") or die("Could not connect: ".mysql_error()); I placed this code inside…
iamauser
  • 11,119
  • 5
  • 34
  • 52
1
vote
1 answer

MySQL DataConnections not closing/pooling

I am working on completely redeveloped website and sales system and have come up against this Max_connections issue surprisingly quickly. I posted this question: Closing/Pooling MySQL ODBC connections Recently, but have since tried a few other…
Jamie Hartnoll
  • 7,231
  • 13
  • 58
  • 97
1
vote
1 answer

Localhost (using xampp) connecting to a remote DB?

I've been trying to connect to a remote DB hosted elsewhere, not my my PC as localhost, but whenever I do (using the exact same password, host, etc as the live server), I get these errors: Warning: mysql_connect() [function.mysql-connect]: Premature…
user938787
1
vote
1 answer

Using Python to update Mysql Table with subqueries

I am trying to update a table multiple times using for loop. My code is as follows: prmtr='Energy Sales(GWh)' try: connection = mysql.connector.connect(host='localhost', database='Tariff_True_Cost', user='root', …
ar ia
  • 17
  • 4
1
vote
2 answers

I'm doing a PHP login page taking posted vars and putting in mysql_connect params. Is it a bad practice?

first of all, thanks for your time. Like the subject says... i'm doing a login page, but every search send me to the same code: use posted user & pass connect to mysql search for the user & pass posted if returns records then ok else bad…
FoxEdu
  • 25
  • 1
  • 3
1
vote
1 answer

How to safeguard my mysql_connect password (My database server's password)?

*This question is for NON-local host's. *I am using a web-host service. NOT my personal server. To use mysql_connect, to connect to a database's server, one needs to create a php file and save it in the web host's server. This file must have (within…
Omar
  • 11
  • 1
1
vote
2 answers

Python Mysql-Connector. Which is better connection.close() or connection.disconnect() or connection.shutdown()

I have a question and I hope that someone could help me. To give you some context, imagine a loop like this: while True: conn = mysql.connector.connect(**args) #args without specifying poolname conn.cursor().execute(something) conn.commit() …
1
vote
2 answers

How to connect PHP to MySQL as an interactive connection is it will use interactive_timeout instead of wait_timeout?

So, MySQL has wait_timeout and interactive_timeout. By default, MySQL connections we make use wait_timeout. I want to use interactive_timeout for connection with users so the timeout won't disturb user interaction. How can I create an interactive…
Aminah Nuraini
  • 18,120
  • 8
  • 90
  • 108
1
vote
1 answer

Can't create temporary tables through Python (Mysql.Connector)

I have a query of the following format, DROP TABLE X; CREATE TEMPORARY TABLE IF NOT EXISTS X (SELECT * FROM TABLE); SELECT A,B,C FROM X; However, if I run this in Python using mysql connector. I get the following message, 'No result set to fetch…
1
vote
4 answers

MySQL Connect Function doesn't work?

I am trying to connect to my database, but it shows me error in the mysql_connect function. The error is: Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\xampp\htdocs\Connect.php:12 Stack trace: #0…
TheGrimBoo
  • 199
  • 1
  • 4
  • 14
1
vote
5 answers

What is the typical speed that PHP connects to MySQL?

Say I have very standard mysql connection code: $dbhost = '192.168.1.99'; $dbuser = 'dbuser'; $dbpass = 'dbuserpass'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); $dbname =…
slim
  • 2,545
  • 1
  • 24
  • 38
1
vote
3 answers

MySQL connect failed. Can't connect to MySQL server on 'http' (4)

I try to connect my android application using JSON Parser to the web hosting. But whenever I try to connect (even just open using url in the browser) I will get the error message.
gpsrosak
  • 107
  • 1
  • 10