Skip to main content

Posts

Showing posts with the label SQL

MYSQL FORMATED OUTPUT

Most of the time when we run select statement in mysql command line if number of columns are more then we get output that is unread able from that command line ,get mysql select output formated sql select output vertically formated using following command select * from test\G; by appending \G at the end of your select statement you will get result as following *************************** 1. row *************************** column1: abc column2: test column3: admin column4: 2012-11-15 column5: test@gmail.com column6: test column7: test2 7 rows in set (0.00 sec)

PHP DATABASE CONNECTION

//connecting to db $conn = mysql_connect("localhost","peter","abc123"); if (!$conn) { die('Could not connect: ' . mysql_error()); } // some code mysql_close($conn); // closing connection //query db $data=$conn->query("SELECT * FROM myTable "); foreach($data as $row) { print_r($row); }

SQL Built-In Functions, String Functions,SOUNDEX

Returns a four-character (SOUNDEX) code to evaluate the similarity of two strings. Syntax SOUNDEX ( character_expression ) Arguments character_expression Is an alphanumeric expression of character data. character_expression can be a constant, variable, or column. Return Types varchar  **  SOUNDEX converts an alphanumeric string to a four-character code to find similar-sounding words or names. The first character of the code is the first character of character_expression and the second through fourth characters of the code are numbers. Vowels in character_expression are ignored unless they are the first letter of the string. String functions can be nested **   Examples The following example shows the SOUNDEX function and the related DIFFERENCE function. In the first example, the standard SOUNDEX values are returned for all consonants. Returning the SOUNDEX for Smith and Smythe returns the same SOUNDEX result because...

SQL Buil-In Functions, String Functions,NCHAR

Returns the Unicode character with the specified integer code, as defined by the Unicode standard Syntax NCHAR ( integer_expression )   Arguments integer_expression Is a positive whole number from 0 through 65535. If a value outside this range is specified, NULL is returned.   Return Types nchar Examples A. Using NCHAR and UNICODE The following example uses the UNICODE and NCHAR functions to print the UNICODE value and the NCHAR (Unicode character) of the second character of the København character string, and to print the actual second character, ø .  DECLARE @nstring nchar(8) SET @nstring = N'København' SELECT UNICODE(SUBSTRING(@nstring, 2, 1)),    NCHAR(UNICODE(SUBSTRING(@nstring, 2, 1))) GO Here is the result set.  ----------- - 248         ø(1 row(s) affected) B. Using SUBSTRING, UNICODE, CONVERT, and NCHAR   The following example uses the ...

SQL Buil-In Functions, String Functions,ASCII

Returns the ASCII code value of the leftmost character of a character expression. Transact-SQL Syntax Conventions Syntax ASCII ( character_expression ) Arguments character_expression Is an expression of the type char or varchar . Return Types int  Examples  SET TEXTSIZE 0 SET NOCOUNT ON -- Create the variables for the current character string position -- and for the character string. DECLARE @position int, @string char(15) -- Initialize the variables. SET @position = 1 SET @string = 'Du monde entier' WHILE @position <= DATALENGTH(@string)    BEGIN    SELECT ASCII(SUBSTRING(@string, @position, 1)),       CHAR(ASCII(SUBSTRING(@string, @position, 1)))     SET @position = @position + 1    END SET NOCOUNT OFF GO Here is the result set. ----------- - 68          D          ...

Stop SQL Injection Attacks Before They Stop You

This includes How SQL injection attacks work Testing for vulnerabilities Validating user input Using .NET features to prevent attacks Importance of handling exceptions Armed with advanced server-side technologies like ASP.NET and powerful database servers such as Microsoft ® SQL Server ™ , developers are able to create dynamic, data-driven Web sites with incredible ease. But the power of ASP.NET and SQL can easily be used against you by hackers mounting an all-too-common class of attack—the SQL injection attack. The basic idea behind a SQL injection attack is this: you create a Web page that allows the user to enter text into a textbox that will be used to execute a query against a database. A hacker enters a malformed SQL statement into the textbox that changes the nature of the query so that it can be used to break into, alter, or damage the back-end database. How is this possible? Let me illustrate with an example. ...

Configure Database Mail

By default we will use port 25 to configure database mail, which is usually blocked by windows firewall for security reason, try the following. 1 . Disable firewall and test if databasemail sends email. 2 . Make an exception in the windows firewall. Or this also happens when you use wrong port numbers, Just as an example use these values when setting up a database mail feature: You need to have a gmail account, which can be created free if you go to gmail.com, you can send email using gmail service free of cost :) So you can try this example and it works perfect. In database mail, first create profile, and when you create an account, use these values. Give Account name: SQL Server Alerts System Description: XYZ Outgoing mail Server ( SMTP) email id: youremailid#gmail.com ( should have gmail.com) Display Name : SQL Server Reply email : can leave blank Server name : smtp.gmail.com ( this is really important) port no : 587 ( on many website this is given as 465 which is wrong, use 58...