mysql

Function to sanitize input values PHP

I use this: function safeClean($n) { $n = trim($n); if(get_magic_quotes_gpc()) { $n = stripslashes($n); } $n = mysql_escape_string($n); $n = htmlentities($n); return $n; } To prevent any type of MySQL injection or anything like that. Whenever I use it to wrap around $_POST like this: $username ...

mysql_query() returns returns true, but mysql_num_rows() and mysql_fetch_array() give "not a valid resource errors

Here is the code in question: From index.php: require_once('includes/DbConnector.php'); // Create an object (instance) of the DbConnector $connector = new DbConnector(); // Execute the query to retrieve articles $query1 = "SELECT id, title FROM articles ORDER BY id DESC LIMIT 0,5"; $result = $connector->query($query1); echo "vardump...

how to ensure comparison is case sensitive?

Hi there, im trying to do a comparison in MYSQL but wish for it to be case sensitive ex: $userID="test" $q = db_query("select * from users where user_id = '" . $userID . "'"); In DB: userid = "TEST" Ho do i go about making sure the mysql query does not return TRUE for this query as the userid varialbe doesnt match the case of th...

MySQL friends table

I have a MySQL DB in which I store data about each user. I would like to add a list of friends for each user. Should I create a table of friends for each user in the DB or is there a better way? ...

Updated Timestamp field in MySQL through PHP

All, I have a database table in mysql with a field that is of "TIMESTAMP" type. I need help writing the SQL query to update the field with the current timestamp. UPDATE tb_Test set dt_modified = ????? Thanks, ...

OpenJPA & MySQL persist wrong encoded characters

Hi all, my mysql db has character encoding utf8. In QueryBrowser i can see special characters are correct. In appplication using openjpa i can see the same values also correct. But when I persist object into DB, I have correct values in application but incorrect in DB! When I restart application that special characters in application ar...

php mysql timestamp

I need to track the date and time a user was created in my mysql database. I have column called 'created' and the data type as TIMESTAMP. The problem is that when a user changes their password or other information the TIMESTAMP value changes. How can I set this to not change???? ...

Quality questionnaire php mysql graphipcs

Hi, i'm making a questionnaire about a service quality, its contains the options (poor, regular, good, very good). It's contains 6 questions (radio button) and a suggestion box (textbox). In the table of the database i created 6 rows for questions, 1 for suggestion and 1 for date (a friend of mine tole me to use this but i didn't get why...

php / mysql / javascript mindate and maxdate

Hi, In .net, there are the static properties DateTime.MinDate, and DateTime.MaxDate that conveniently return the minimum and maximum valid dates for a DateTime object. I'm dabbling in web programming right now, using php + mysql + javascript. There doesn't seem to be the same convenient min/max date values in that programming environme...

Mysql InnoDB performance optimization and indexing

Hello everybody, I have 2 databases and I need to link information between two big tables (more than 3M entries each, continuously growing). The 1st database has a table 'pages' that stores various information about web pages, and includes the URL of each one. The column 'URL' is a varchar(512) and has no index. The 2nd database has a ...

Get the First And Last Date of Next Month in MySQL

How can I get the first and last day of next month to be used in the where clause? ...

MySQL Search Within Database (Table Search)

Alright, I'm trying to write a piece of code (PHP and SQL), or rather a search query to display all the tables that contain a certain prefix. Something like what is displayed below (but is obviously incorrect) SELECT TABLES LIKE chat_ So any table that has the chat prefix, would be displayed. I plan on formatting the output, so it's n...

Removing part of a string in PHP

I'm trying to take a query: SHOW TABLES; which will display a bunch of tables with the chat_ prefix. I want to remove the chat_ prefix from the string, format the variable (with a link), and display it. How is this accomplished? ...

How to manually build mysql cache

I have a table of over 150,000 rows of which most would be updated daily. I have mysql caching turned on so the pages load faster however everytime the database is updated the pages load slow again, which I assume is the cache building itself again. So at the moment I have resorted to doing a wget -m --delete-after http://localhost/ on...

mysql inserts & updates optimized

This is an optimization question, mostly. I have many forms on my sites that do simple Inserts and Updates. (Nothing complicated) But, several of the form's input fields are not necessary and may be left empty. (again, nothing complicated) However, my SQL query will have all columns in the Statement. My question, is it best to optimi...

Killing the mysqld process

I have a table with ~800k rows. I ran an update users set hash = SHA1(CONCAT({about eight fields})) where 1; Now I have a hung Sequel Pro process and I'm not sure about the mysqld process. This is two questions: What harm can possibly come from killing these programs? I'm working on a separate database, so no damage should come to o...

Way to store dates with missing days/months in mysql (php)

I want to store dates in mysql so I set the table to be of type 'Date', which is fine but mysql requires that the full date is provided YYYY-MM-DD. However some of my data does not include day and some is missing the month. Now I could just use a varchar(10) field, but then its difficult to run date based queries on the data. Is there ...

In Django, how do I filter where language column = "null"?

MyTable.objects.filter(where language column = null) How can that be done? Thanks. ...

How can i get the seed value of an identity column in MySql

To get the seed and step values of an identity column in sql server i can use this syntax SELECT ColumnName = name, Seed = seed_value, Step = increment_value FROM sys.identity_columns So far in MySql i have found that if i use this syntax SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE auto_increment IS NOT NULL I can at least fi...

problem with unicode in javaEE and save question mark in database

when i insert persian information with use JEE6(JSF and JPA) my information save question mark for example "علی" ===> "???" my database is Mysql and my table is UTF-8 . when insert persian data directly in database is correct and save correct. i know that with change one property in JEE my problem go to solved but i don`t know where ...