bonjour,
j'ai une requete create database qui fonctionne mais si j'indique une variable a la place du nom ca me colle une erreur.
ma requete :
	
	| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 
 |  
$con = mysql_connect("localhost","root","passe root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
if (mysql_query("CREATE DATABASE '".$nom_base2."' ",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }
 
mysql_close($con); | 
 si je place :
	
	if (mysql_query("CREATE DATABASE  ma_base ",$con))
 il me crée bien une base nommée ma_base mais le but etant
de créer une base comportant le nom retenue dans la variable $nom_base2
l'erreur :
	
		
			
			
				Error creating database: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''bd-kn-NGY4C2FR'' at line 1
			
		
 
	 
 merci
-------------------
bon j'ai reussi en supprimant les ' et en placant ` autour de la variable.
maintenant je souhaite ajouter l'user et le password qui va bie :
	
	| 12
 3
 4
 5
 6
 7
 
 | <?
if ("CREATE USER '$nick_handle'@'%' IDENTIFIED BY '$password2';
     GRANT USAGE ON * . * TO '$nick_handle'@'%' IDENTIFIED BY '$password2' ;
     CREATE DATABASE IF NOT EXISTS `$nom_base2` ;
     GRANT ALL PRIVILEGES ON `$nom_base2` . * TO '$nick_handle'@'%';"
     mysql_query($con));
?> | 
 mais je doit avoir une erreur car ca ne passe pas.
merci
-----------------------
alors j'ai ajouté localhost et la j'ai une erreur :
	
	| 12
 3
 4
 
 | if (mysql_query("CREATE USER '$nick_handle'@'localhost' IDENTIFIED BY '$password2';
                 GRANT USAGE ON * . * TO '$nick_handle'@'localhost' IDENTIFIED BY '$password2' ;
                 CREATE DATABASE IF NOT EXISTS `$nom_base2` ;
                 GRANT ALL PRIVILEGES ON `$nom_base2` . * TO '$nick_handle'@'localhost';",$con)) | 
 
	
		
			
			
				Error creating database: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GRANT USAGE ON * . * TO 'yRgOyuvO'@'localhost' IDENTIFIED BY 'd41d8cd98f00b204e9' at line 2
			
		
 
	 
 
						
					
Partager