This question already has answers here:
Slow performance MySql
(2 answers)
Closed 6 years ago.
i am buiding a automatic create website system...when i am installing web for my customer, at step i am excute the my sql file i am using like this :
# MySQL with PDO_MYSQL
$db = new PDO("mysql:host=$mysqlHostName;dbname=$mysqlDatabaseName", $mysqlUserName, $mysqlPassword);
$query = file_get_contents($local_sql); //Local file abc.sql
$stmt = $db->prepare($query);
if ($stmt->execute()){
My problem is i have up to 117 table need to create and many many insert sql on this file.
Everytime i buidling 2 or more than website it freeze my server and let it dead.
My question is have any solution ? can excute a big sql file like that faster the way i am using ?
Sorry if my english so bad.
Thank all !
Try to execute your queries one after another. Parse SQL file and execute queries in loop like this:
$queries = explode(';', $query);
foreach ($queries as $query) {
$stmt = $db->prepare($query);
$stmt->execute();
}
Related
This question already has answers here:
Can I mix MySQL APIs in PHP?
(4 answers)
Closed 4 years ago.
I am trying to convert a file name into a binary data type by using sqlsrv and save it in a mysql database but I receive this error:
fatal-error-call-to-undefined-function-sqlsrv-connect
My PHP code is:
$conn=mysqli_connect("localhost","root","","musiccloud");
if(!empty($_FILES['file'])){
$ext = pathinfo($_FILES['file']['name'],PATHINFO_EXTENSION);
$image =$ext;
Echo"File Copied Successfully";
sqlsrv_query($conn, 'INSERT INTO musiclist(name) VALUES (?)', array(
array($ext, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING,
SQLSRV_SQLTYPE_BINARY)
));
echo "successfully uploaded";
}
You state that your trying to insert to mysql - but are using sqlsrv_query
this is for MS Sql Server try http://php.net/manual/en/mysqli.query.php
you used mysqli driver to connect to your DB that can only connect to MySQL/MariaDB.
if you are using SQL Server then you have to use PDO or sqlsrv_connect in your case.
This question already has answers here:
mysqli last insert id
(3 answers)
Closed 5 years ago.
I am executing the following sql code
$query = "INSERT INTO order_shipping_addresses(user_customer_id, shipping_address_details, created, modified) VALUES('".$_SESSION['user_id']."', '".serialize($address)."', '".$created."', '".$modified."')";
$connection = $this->establish_connection();
$data = $connection->query($query);
$order_shipping_address_id = last_insert_id();
$connection->close();
What i wanted was when this query is executed i wanted the row id in which this data is inserted, i am using the last_insert_id() function but i am getting an error of Call to undefined method mysqli::lastInsertId()
how to extract all the data from the $data variable and also the row id in which the data is inserted. I am using PHP OOP style.
Thanks in advance..
You want to use $connection->insert_id
This question already has answers here:
How to debug a query in extbase?
(11 answers)
Closed 1 year ago.
I am new to Typo3. I am using 6.1 version of it.
I need to display the MySQL query generated from the query object. Please let me know how can I do that?
Below is the code snippet that is in my repository class.
$query = $this->createQuery();
$query->getQuerySettings()->setRespectStoragePage(false);
$query->matching(
$query->equals('id',intval($id))
);
return $query->execute();
I need to display the MySQL query before executing and returning the result of the query.
Please let me know how can I do that.
Thanks in advance.
in extbase its very hard to display the last query.
you might try the normal TYPO3 way, but you have to execute the query before you can do that:
$GLOBALS['TYPO3_DB']->store_lastBuiltQuery = 1;
//query
// the complete SQL-Statement
echo $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
Another way is to go into the buildQuery(array $sql) just before the return statement and add this snippet:
if (in_array("your_table_name", $sql['tables'])) {
var_dump($statement);
print_r($statement);
}
You can find the buildQuery method here:
TYPO3 ver.: 4.x: typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php
TYPO3 ver.: 6.x: typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php
Edit:
A very good method is to just misspell the column name. For example: Column is called test, call it testsdffq. The query will fail and it will show you the whole query.
May be this will help.
Make sure the following is set in localconf.php:
$TYPO3_CONF_VARS['SYS']['sqlDebug'] = '1';
$TYPO3_CONF_VARS['FE']['debug'] = '1';
try
$res = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_xmluploader_xml_import_tree', 'xml_import_id='.$xml_import_id);
t3lib_div::debug($res);
Result will be output of the query in the frontend. You can then execute it in MySQL for debugging.
This question already has answers here:
How to get a list of databases?
(4 answers)
Closed 11 months ago.
How can I get a list of all the MySQL databases that exist on a server using PHP?
$result = mysqli_query($db_conn,"SHOW DATABASES");
while ($row = mysqli_fetch_array($result)) {
echo $row[0]."<br>";
}
$dbcnx = mysql_connect ($dbhost, $dbusername, $dbpassword);
$result = #mysql_query('SHOW DATABASES');
while ($row = mysql_fetch_array($result)) {
print_r ($row)
}
At the MySQL prompt, SHOW DATABASES does what you want.
You can run this command as a query from PDO or the native PHP MySQL library and read the returned rows. Pretend it is a normal select.
You will only see the databases that the account used to connected to MySQL can see.
The MySQL command for this is
SHOW DATABASES
See the manual for more info on the SHOW command
Just use SHOW DATABASES.It will show all the databases present in your MySQL.
Write the SQL query:
show databases
This question already has answers here:
How to get Insert id in MSSQL in PHP?
(3 answers)
Closed 10 years ago.
I want to get last inserted id of particular table. can any one tell me how i can get that?
we have mysql_insert_id() in mysql. Do we have similar kind of function in sql server 2008?
something like this works very nicely
$sql = "insert into tables(field) values (value);SELECT SCOPE_IDENTITY()";
$db = getConnection();
$results = mssql_fetch_assoc(mssql_query($sql));
$lastid=$results['computed'];
I made this function to make it easy :)... if you have more then one db resource just pass that into the mssql_query request. This will retrieve the last unique id generated on that resource connection.
mssql_query("insert into data(name) values('bob')");
$id = getLastId();
function getLastId() {
$result = mssql_fetch_assoc(mssql_query("select ##IDENTITY as id"));
return $result['id'];
}