0

I tried to create a database in utf8 in order to collect some informations in arabic and I made 2 php documents, but some errors occur. It displays :

 *Parse error: syntax error, unexpected '"CHARACTER SET 'utf8'"'(T_CONSTANT_ENCAPSED_STRING) in C:\...\Setup.php on line 13

(Line 13 is this line : " $resultat=mysql_query("CREATE DATABASE ".$base "CHARACTER SET 'utf8'", $id ); "

First php document : Parametres.php

  $host="localhost"; 
  $user="user";
  $pass="pass";
  $base="Databasename";

Second php document :

  include("Parametres.php");<br>
  $id=mysql_connect($host,$user,$pass);<br>
  $resultat=mysql_query("DROP DATABASE IF EXISTS ".$base,$id);<br>
  $resultat=mysql_query("CREATE DATABASE ".$base "CHARACTER SET 'utf8'", $id );<br>

...

Thank you in advance !

Alastair McCormack
  • 26,573
  • 8
  • 77
  • 100
Olscream
  • 127
  • 1
  • 14
  • 2
    You are missing the string concatenation operator `.`. A space character inside the CHARACTER SET string is also missing – knittl Dec 19 '15 at 11:34

1 Answers1

0

You should escape the single quote like this,Change your code as below

 $sql = "CREATE DATABASE ".$base." DEFAULT CHARACTER SET utf8
  DEFAULT COLLATE utf8_general_ci";
mysql_query($sql, $id );

Refer this for create database using php mysql

Community
  • 1
  • 1
mahesh
  • 1,311
  • 1
  • 13
  • 26