Skip to main content

Posts

Showing posts with the label mysql

PHP unlink function

This is the code $query = mysql_query("SELECT avatar FROM users WHERE UserID = ".$userID.""); $row = mysql_fetch_array($query); $user_avatar = trim($row['avatar']); unlink($user_avatar);

MySQL Query doesn"t update rows

I've got a weird problem here. I've been trying to find out whats wrong for several hours now. I've got a function that should update a table in my database and set the "date_vente" (date_sold for english) to NOW(). The query is mighty simple but it keeps reporting 1 matched row, 0 changed.

Scaling Drupal

I am working on a Drupal based site and notice there are a lot of seperate CSS and js files. Wading though some of the code I can also see quite a few cases where many queries are used too. What techniques have you tried to improve the performance of Drupal and what modules (if any) do you use to improve the performance of Drupal 'out of the box'? Source: Tips4all

MySQL - ignore insert error: duplicate entry

I am working in PHP. Please what's the proper way of inserting new records into the DB, which has unique field. I am inserting lot of records in a batch and I just want the new ones to be inserted and I don't want any error for the duplicate entry. Is there only way to first make a SELECT and to see if the entry is already there before the INSERT - and to INSERT only when SELECT returns no records? I hope not. I would like to somehow tell MySQL to ignore these inserts without any error. Thank you Source: Tips4all

MySQL INTO OUTFILE overide existing file?

I've written a big sql script that creates a CSV file. I want to call a cronjob every night to create a fresh CSV file and have it available on the website. Say for example I'm store my file in '/home/sites/example.com/www/files/backup.csv' and my SQL is SELECT * INTO OUTFILE '/home/sites/example.com/www/files/backup.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM ( .... MySQL gives me an error when the file already exists File '/home/sites/example.com/www/files/backup.csv' already exists Is there a way to make MySQL overwrite the file? I could have PHP detect if the file exists and delete it before creating it again but it would be more succinct if I can do it directly in MySQL. Source: Tips4all

Alternative to mysql_real_escape_string without connecting to DB

I'd like to have a function behaving as mysql_real_escape_string without connecting to database as at times I need to do dry testing without DB connection. mysql_escape_string is deprecated and therefore is undesirable. Some of my findings: http://www.gamedev.net/community/forums/topic.asp?topic_id=448909 http://w3schools.invisionzone.com/index.php?showtopic=20064 Thank you in advance! Source: Tips4all

Where and when to open a database connection

I am working on implementing use of the mysql class found here in an existing script. The script almost always needs to interact with the database, even if there are times when it does not. What is the best practice in this case? Should I open a connection and keep that open until the end of the script or should I open a connection when I need one, closing it when I'm done, to avoid opening a connection when the script does not need it? Source: Tips4all

"Did you mean” feature on a dictionary database

I have a ~300.000 row table; which includes technical terms; queried using PHP and MySQL + FULLTEXT indexes. But when I searching a wrong typed term; for example "hyperpext"; naturally giving no results. I need to "compansate" little writing errors and getting nearest record from database. How I can accomplish such feaure? I know (actually, learned today) about Levenshtein distance, Soundex and Metaphone algorithms but currently not having a solid idea to implement this to querying against database. Best regards. (Sorry about my poor English, I'm trying to do my best) Source: Tips4all

What are good PHP and MySQL type Blogs to read?

I searched and found many topics similar to this on Stackoverflow, but they were all for languages that I do not use. I am interested in reading good blogs with an RSS feed in topics related to PHP , MySQL , Javascript , jQuery . I have a few listed below so far, please share with me any blogs worth reading and subscribing to with any of these web related topics. Here are some I enjoy now... http://buildinternet.com http://davidwalsh.name http://www.9lessons.info http://blog.perplexedlabs.com http://blog.agilephp.com http://www.barattalo.it http://papermashup.com Source: Tips4all