Hello. I use the php code.

$username = "exxtazzy"; $password = "m2uyYd5KYeiTdYeu3fYt024tup=PQI15nuIo8evh"; $hostname = "localhost"; $dbName = "exxtazzy"; /* создать соединение */ mysql_connect($dbName, $username, $password) or die ("Не могу соедениться". mysql_error());; $res =mysql_query("CREATE TABLE phone_list( id INT PRIMARY KEY, name varchar(15), Phone varchar(6) ",NULL ) or die ("Ошибка соеденения". mysql_error()); echo $res; mysql_close()or die ("Не могу закрыться". mysql_error());; ?> 

I enter the correct password and entered it when transferring from hosting to a local server. How so why I can not connect to the database? How so why I can not connect to the database? Password changed so do not try to do something.

  • Is mysql itself running? - ghost rider
  • ping exxtazzy host, and check if the port from mysql is open - binliz
  • die ('Connection failed:'. mysql_error ()); wrote off the line and now pops up Connection error: I imported the database from the site, so it should be launched - exXtaZzy
  • My current code is $ username = "exxtazzy3_nick"; $ password = "m2uyYu5KYeiTdYeu3fYQ024 ~ up = PQI1InuIo8evh"; $ hostname = "localhost"; $ dbName = "products"; / * create connection * / mysql_connect ($ hostname, $ username, $ password) OR DIE ("I can not create a connection"); die ('Connection failed:'. mysql_error ()); "CREATE TABLE 'phone_list' ('id' INT PRIMRY KEY 'name' varchar (15) 'Phone' varchar (6));" ?> - exXtaZzy
  • one
    > localhost> do not try to do something. That's how everyone ran away. - istem

3 answers 3

Firstly:

 $username = "exxtazzy3_nick"; $password = "m2uyYu5KYeiTdYeu3fYQ024~up=PQI1InuIo8evh"; $hostname = "localhost"; $dbName = "products"; / создать соединение / mysql_connect($hostname,$username,$password) OR DIE("Не могу создать соединение " . mysql_error()); 

And secondly: what does mysql_error () say? Nothing? And that from your comment is not clear.

In the fact that you brought there bjaka. Regardless of the result of the connection, die () is executed and the script is terminated. And what about the "CREATE TABLE ..."?

  • I copied your code from here and didn’t get any error, but in the database I didn’t find a table with the name phone_list - exXtaZzy
  • So, it means mysql_connect does not detect any errors. Is there a phone_list in the products database? If you connect mysql products from the console (parameters --user = exxtazzy3_nick --password = m2uyYu5KYeiTdYeu3fYQ024 ~ up = PQI1InuIo8evh) and say show tables; , will this same phone_list be on the list? - alexlz
  • There is no base for the products, there is another base; by the way, I changed the $ dbName variable to the name of my base, there is no table. - exXtaZzy
  • So if you do not swear at mysql_connect, then it may be worth seeing if this table is there? For example, run a query like $ result = mysql_query ("show tables"); and display the results of this query? - alexlz
  • 2
    I will repeat the question @alexlz> And what about the "CREATE TABLE ..."? make mysql_query ("CREATE TABLE 'phone_list' ('id' INT PRIMRY KEY 'name' varchar (15) 'Phone' varchar (6));"); suddenly turn out;) - KerLeada
 mysql_select_db($dbName); 
  • (35 minutes ago) alexlz, brought up echo, I have neither false nor true pops up. And when using mysql_query there is no need to enter a password and login. And how does she connect with the database? - exXtaZzy
  • php.net/manual/ru/function.mysql-query.php link_identifier MySQL connection. If the connection identifier has not been specified, the last connection opened by mysql_connect () is used. If such a connection was not found, the function will attempt to create one as if mysql_connect () were called without parameters. If the connection was not found and could not be created, an error of the E_WARNING level is generated. And, by the way, you fixed the errors in the query "CREATE TABLE ..."? - alexlz
  • And how can a connection be active if I just turned on the server. What is interesting, I do not get an error of the E_WARNING level. I just do not pop up anything. I corrected the code that you said. $ res = mysql_query ("CREATE TABLE phone_list (id INT PRIMARY KEY, name varchar (15), Phone varchar (6)", NULL) or die ("Connection Error". mysql_error ()); echo $ res - exXtaZzy
  • What does it mean "just now turned on the server"? In general, it is not very clear what is happening. And edit the text of the script in question so that it reflects the current state. - alexlz
  • I have a site on the local hosting, so to open and debug the site, you need to start the server. when I run the script, no error pops up and the table is not created. I just do a proper search in imm.io/WVMc - exXtaZzy

If you just started using php , then immediately learn PDO . For then it will not be customary to go.

For a start, we need php from version 5.

And then use this code:

$db = new PDO('mysql:host=хост;dbname=база','пользователь','пароль');

Well, for example, how to choose records from MySQL later:

$db->query("SELECT * FROM table");

In general, read these articles:

  1. PDO - 1
  2. PDO - 2
  • PDO is a panacea for curvature and non-coercion of programmers. A person who successfully works with mysql_ * will successfully master other wrappers. But a person starting with PDO, as a rule, has no idea at all about low-level work with databases. I would not trust my projects like this. - istem
  • @istem are you yourself aware of the low-level database operation? how deep? But maybe you wouldn't trust the one who didn’t see a 8 "diskette or didn’t use a punched card? - zb '
  • Stupid argument. - istem
  • this is not a dispute, you just said nonsense. - zb '