Ask a PHP installer for minor problems
I write a PHP installer that wants to generate the database directly from this page
I assign the SQL statements to the array separately.
$sql []= "CREATE Table A ...";
$sql []= "CREATE table B ...";
$sql []= "CREATE TABLE C ...";
Then use the Foreach Loop to execute
foreach ($sql as $val)
{
mysql_query ($val);
}
--------------------------------------------------
There's nothing wrong with building a library.
Then I want to attach some initial data when the program is installed, that is, add several articles.
I also wrote the INSERT statement in $sql[]
But the article is relatively long and the article is the code class is very easy to conflict has been unsuccessful so ... Come and ask.
------Solution--------------------
The cause of the conflict is not escaped as follows:
$article = "I m John";
$sql = "INSERT into articles values ('". Addslashes ($articles). "')";
------Solution--------------------
You'd better post the error messages you've encountered. Otherwise there is no solution.
mysql_query ($val) or Die (Mysql_error ()); Change it.
------Solution--------------------
What does it mean to assign a value that is not an array? I guess it's probably all about your single-quotes.
------Solution--------------------
Statement is complex to escape statements, especially if there is a single double quotation mark can cause conflicts
Upstairs have said, for the assignment and other issues to give more professional questions to explain
For example, the error of the report, debugging is also the most important step to solve the problem,
There is no error, try to get the error output, with the wrong to find the problem
------Solution--------------------
You #4 SQL instructions that contain a representation of a PHP variable, such as a $words []
So you have to deal with it before you put it in the array.
1, if it is php5.3 above, then relatively simple, just
$sqls [] =<<< ' SQL '
SQL instructions
SQL;
2, otherwise you need to save each sentence of SQL instruction to a text file separately
and assemble it in a program.
$sqls [] = Str_replace (' $ ', ' \$ ', file_get_contents (' filename '));
Of course you can also use the editing software to manually replace $ into \$
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.