php,sqlRelated issues-Collection of common programming errors


  • Webnet
    php
    I have this code and I need to make this work:if ($handle = opendir(“images/”)) { $i=0;while (false !== ($file = readdir($handle))){if ($file != “.” && $file != “..” && $file != “Recursive Dir_Renfiles_dirname-filename.php”) {$filename[$i]=$file;$i++;}}}//print_r($filename);foreach($filename as $filename){$percent = 0.5;// Content typeheader(‘Content-Type: image/jpeg’);// Get new dimensionslist($width, $height) = getimagesize($filename);$new_width = $width * $percent;$new_height

  • Emanuil Rusev
    php function
    In CakePHP there is a (quite fundamental) method called find. Most of the time this method would return an array but if you pass count as the first parameter the method would return a different data type – an integer.The method is allowed to return various data types.Isn’t that bad?

  • jela
    php
    given the following script<?phpini_set(‘display_errors’,’On’); error_reporting(E_ALL);thisisanerror?>I get the expectedNotice: Use of undefined constant error – assumed ‘error’ in /htdocs/test.php on line 8but if I add something to the script<?phpini_set(‘display_errors’,’On’); error_reporting(E_ALL);errorfunction test () {echo(‘test’);}?>I getHTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.Why am

  • Alan Moore
    php regex
    I’m working on a simple project to teach about XSS. I’m trying to make a regex that will catch <script>alert(‘anything’)</script>;I crafted: <script>alert\(\'[\w!@#$%^&*()-=+]+\’\);</script> but when i try to implement it in php I get errors yet when I try it in a regex tool it says it matches my string.Anyone know how to make a regex that works?Thanks

  • Mr Biscuit
    php session variables if-statement phpmyadmin
    I am trying to create a user login page. Upon successful registration admins are assigned a value of “A” in my database and customers a “C”. Upon successful login customers will be directed to one page and admins to another. I created three session variables, their userId, userFName and their userType. I want to create an if statement to check the value of userType and have tried everything but I still get the error message “Parse error: syntax error, unexpected T_ELSE…on line 74”.`//create a

  • Dominic Rodger
    php variables scope
    I have a function with a big hierarchy:function func(){$a= 0; // Here the variable is 0while(…){echo $a; // gives me always 0for(…){if(…){if(…){$num = func3();$a = $num; // this $a does not corrospond to $a in the beginning}}}} }Does anyone know how I can change the value of $a from the nested scopes?

  • skaffman
    php exception-handling
    When throwing a new exception is it best to simply return true if no exception needs to be thrown. Alternatively is it best to return false instead of throwing an exception. Im using php.

  • noloader
    php sqlsrv
    I have experience with mysql databases and have successfully connected to them with a couple dozen projects. Now, I’m having trouble connecting to a SQL Server 2007. This works: <?php phpinfo(); ?> and the sqlsrv and pdo_sqlsrv sections appear on this page. Here’s the code that I’m using to connect: <?php $serverName = “serverName\sqlexpress”; //serverName\instanceName $connectionInfo = array( “Database”=>”dbName”, “UID”=>”userName”, “PWD”=>”password”); $conn = sqlsrv_connect(

  • Chimera
    php function types parameters casting
    This might sound like a silly question to many of you, but it keeps me wondering why PHP does not allow typecasting in its function parameters. Many people use this method to cast into their parameters:private function dummy($id,$string){echo (int)$id.” “.(string)$string }Orprivate function dummy($id,$string){$number=(int)$id;$name=(string)$string;echo $number.” “.$name; }But looking at many other programming languages, they accept typecasting into their function parameters. But doing this in PH

  • Sumurai8
    php apache .htaccess codeigniter error-handling
    My website has been slowed down a little last couple of days. I’ve looked into my error log and found lots of these:[Mon Sep 30 00:09:53 2013] [error] [client 66.249.66.205] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace. [Mon Sep 30 00:09:53 2013] [debug] core.c(3120): [client 66.249.66.205] r->uri = /home/mysitecom/domains/mysite.com/public_html/

  • zerkms
    sql postgresql
    select current_timestamp(6), current_timestamp(0) —————————————————- 2012-02-22 16:03:45.988418+13 | 2012-02-22 16:03:46+13——-^ ————^ (date from the future)This query can easily return the timestamp from the future for the second column because of current_timestamp(0) is rounding “mathematically”. This could lead to some unexpected errors, just because the retrieved time is from the future up to 0.5s.So my question is – what is t

  • Ravee
    sql sql-server bulkinsert bcp
    I am trying to bulk insert into the table which has an identity column.But my host file contains empty value for identity column.When I issue ‘bcp’ command,I get an error – Starting copy…SQLState = S1000, NativeError = 0Error = [Microsoft][SQL Server Native Client 10.0]Unexpected EOFencountered in BCP data-fileSQLState = 23000, NativeError = 515Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannotinsert the value NULL into column ‘UNIQUE_ID’, table ‘xx.dbo.yyy’;column does not a

  • John Saunders
    sql sql-server-2008
    I recently had to move a database(sql server 2008) to a different server, and I have noticed that in one of the table, the value of identity column has started to get some unexpected values. its set as identity column with identity increment 1 and identity seed 1. After every 10 consecutive entry or so, it would start from another much higher number and increment by 1 for next 10 entries or so and then jump up to another higher number. I can’t seem to figure out the issue. Sorry for the layman

  • GEOCHET
    sql sql-server sql-server-2005
    I’m rewriting some old stored procedure and I’ve come across an unexpected performance issue when using a function instead of inline code.The function is very simple as follow:ALTER FUNCTION [dbo].[GetDateDifferenceInDays] ( @first_date SMALLDATETIME, @second_date SMALLDATETIME ) RETURNS INT AS BEGIN RETURN ABS(DATEDIFF(DAY, @first_date, @second_date))ENDSo I’ve got two identical queries, but one uses the function and the other does the calculation in the query itself:ABS(DATEDIFF(DAY,

  • Aaron Digulla
    java sql oracle hibernate hql
    I am using oracle 10g and hibernate 3.3.2. I have used regular expression in sql before, now for the first time I am using it in HQL.Query query = getSession().createQuery(“From Company company where company.id!=:companyId and regexp_like(upper(rtrim(ltrim(company.num))), ‘^0*514619915$’ )”);This is my hql, when i run it without regex_like function it runs as expected. But I am not able to execute it with regex_like expression. It says..nested exception is org.hibernate.hql.ast.QuerySyntaxExce

  • babonk
    sql django sqlite django-models
    Django seems to be falsely claiming that I have an error in my SQL syntax. The query runs fine (returning the intended results) in the django dbshell but spawns an error when the query is run through Django. Here is the code (tracebacks follow):#this code is inside the models.Customer.display_sharers() function sharers_by_action_count = Sharer.objects.raw(”’ SELECT wordout_sharer.id, COUNT(actions_of_type.id) AS action_count FROM wordout_customer INNER JOIN wordout_sharerON wordout_sharer.cus

  • Lasse V. Karlsen
    sql
    Is it possible to reorder rows in SQL database? For example; how can I swap the order of 2nd row and 3rd row’s values?The order of the row is important to me since i need to display the value according to the order.Thanks for all the answers. But ‘Order by’ won’t work for me.For example, I put a list of bookmarks in database. I want to display based on the result I get from query. (not in alphabet order). Just when they are inserted. But user may re-arrange the position of the bookmark (in an

  • slf
    sql sql-server operators
    Today while inside a client’s production system, I found a SQL Server query that contained an unfamiliar syntax. In the below example, what does the *= operator do? I could not find any mention of it on MSDN. The query does execute and return data. As far as anyone knows, this has been in the system since they were using SQL Server 2000, but they are now running 2005.declare @nProduct int declare @iPricingType int declare @nMCC intset @nProduct = 4 set @iPricingType = 2 set @nMCC = 230–Buil

  • R-C
    sql sql-server sql-server-2008 tsql
    I’m trying to check index fragmentation in my database using SQL 2008 R2.I’m using the following code, taken from http://msdn.microsoft.com/en-gb/library/ms189858(v=sql.100).aspx with a couple of name changes:USE StockSystem; GO SELECT a.index_id, name, avg_fragmentation_in_percent FROM sys.dm_db_index_physical_stats (DB_ID(), OBJECT_ID(N’dbo.StockItems’),NULL, NULL, NULL) AS a JOIN sys.indexes AS b ON a.object_id = b.object_id AND a.index_id = b.index_id;GOWhen I run it I get the error:Msg 102,

  • casperOne
    sql sql-server schema
    Input:The customer claims that the application (.NET) when querying for some data returns data different from when the customer looks into the data table directly.I understand there could be various reasons and in completely different places. My purpose is not to solve it here, but rather to ask experienced DBAs and DB developers if:Is it possible for a VIEW to show data that does not match the underlying TABLE(s)?What are possible causes/reasons for this? Can an UPDATE statement on a view cause

Web site is in building