• Welcome to Valhalla Legends Archive.
 

Quickie PHP/MySQL tips, little-known to most

Started by Banana fanna fo fanna, June 03, 2003, 07:58 PM

Previous topic - Next topic

Banana fanna fo fanna

1) Use single quotes ( ' ) when you have strings that don't have $values in them. Double quotes for those.

2) Use mysql_pconnect() instead of mysql_connect(), mysql_pconnect() creates persistent connections to the database which reduces the load.

3) You can use $c = new COM("ADODB.Recordset") to use ADO if you want.

Just wanted to post something related to PHP :) Invert please don't delete just because it's not ASP :P

Dumb_Canadian

#1
Quote from: St0rm.iD on June 03, 2003, 07:58 PM
1) Use single quotes ( ' ) when you have strings that don't have $values in them. Double quotes for those.

- Great tip. Using PHP's string literals (Single quotes,) is a great, simple way to increase the performance of large applications that use the alternative. PHP is actually doing a lot of work with strings when you use double-quotes. Even when using the value of a variable, I use string literals, but with the append operator (.), like:


$str = (string) 'there!';
echo('Hi, ' . $str);



Another tip I'd like to add, though, is try your best not to use quoation when you shouldn't. A lot of people don't realize that when you create a variable, intended to be an integer:


$integerContainer = (int) '123';


The quotation is actualy telling PHP you want to put a string literal in the $integerContainer, but at the same time, using the (int) type cast, instruct PHP to declair this container as an integer. Clearly, this is going to give PHP internal head-aches. Instead, consider this:


$integerContainer = (int) 123;
$stringContainer   = (string) 'Hello, world.';


Either should work. But consider using logic such as this:


$integerContainer = (int) '123';
if( $integerContainer == 123 ) {
  echo('True.');
}


This isn't going to happen, because the == operator is asking if the container is of the same type, and value of '123'.

It doesn't happen, because $integerContainer, even though it contains integers, was cast as a String based on the String literal quotes.

Invert

#2
Quote from: St0rm.iD on June 03, 2003, 07:58 PM
Just wanted to post something related to PHP :) Invert please don't delete just because it's not ASP :P

I am not bias towards PHP, I consider it to be better than ASP (not ASP.NET). I don't even like to script in ASP.

Oh and here is a tip: If you want to use a free database when scripting with PHP use PostgreSQL not MySQL.

Stored procedures = good

Dumb_Canadian

#3
Quote from: Invert on June 05, 2003, 05:13 AM
Stored procedures = good


Ah, indeed, indeed! This is why I choose to use Microsoft's SQL Server 2000 for all my RDBMS needs;)

The MySQL group likes to claim full T-SQL support, but technicaly, the MySQL engine doesn't support it in the slightest. They can claim support for it, though, because they ship the InnoDB engine with their package, heh. Regardless, SQL Server 2000 and/or PostgreSQL's where it's at for performance and stability, IMO:)

Banana fanna fo fanna

I agree Postgres is technically superior from what I've heard (.org root database runs on it afaik), but I've never learned it so I can't preach it.

WinSocks

#5
Views Tips:

Views can be used to define numerous combinations of rows and columns from one or more tables. << (Basics whoop dee doo)

- A view is nothin more than a SELECT statement, unlike alot of people mistaken it as a actual physical Table in the database, it's just a collection of specified rows and columns from other tables.

- A View can contain a max of 1,024 colums

- Defaults, Triggers aan rules are  useless to try to put into a view, considering they are disalllowed to associate with view functions. but the only exception to this rule is the new "INSTEAD OF" trigger.

- Views Cannot be created using the "ORDER BY" clause unless they use the "TOP" clause.

- Views Cannot be Created using the "COMPUTE BY" or "SELECT INTO" Clauses.

- Temporary Views Cannot be created (stupid newbs like to think that ;) )

- Views can be nested up to 32 levels.

- Local Partitioned Views do no tneed to use "CHECK" constraints. NOt using "CHECK" constraints will aslo provide the same results as with using a "CHECK" constraint, except that the Query Optimizer will have to preform a lengthy search against all member tables meeting the query search condition. Using "CHECK" constraints will reduce the cost of queries

- Be sure that in a Local Partitioned View that Primary Keys are defined on the same column for each member table.